<template>
	<public-view navType="other2" :navTitle="page_title">
		<view class="content">
			<view class="top-tab w-100 flex a-i-c j-c-b">
				<view class="tablist flex a-i-c">
					<block v-for="(item, index) in tab_list" :key="index">
						<view class="item f-s-32 flex a-i-c j-c-c" @click="changeTabId(item)" :class="tab_id === item.id ?'active':'unacitve'">
							{{item.name}}
							<view class="line-bottom" v-if="tab_id === item.id"></view>
						</view>
					</block>
				</view>
				<picker class="flex a-i-c color-696969 f-s-26" :range="distance_list" @change="changeD">
					{{distance_text||"默认距离"}}
					<image class="icon" src="@/static/images/select-icon.svg" mode=""></image>
				</picker>
			</view>
			<view class="compont-list-box">
				<block v-for="(item, index) in gas_list" :key="index">
					<view class="items flex f-d-c">
						<view class="top flex a-i-c j-c-b">
							<view class="flex a-i-c f-s-30">
								{{item.name||""}}
							</view>
							<view class="juli-box f-s-24 color-333 flex a-i-c" @click="$location.openMapLocation(item.lat,item.lng)">
								<image class="l-icon" src="@/static/images/blcak-location-icon.svg" mode=""></image>
								{{item.distance||0}}km
							</view>
						</view>
						<view class="center-info flex a-i-c">
							<image class="image" :src="item.images" mode=""></image>
							<view class="info-box flex f-d-c" style="flex: 1;">
								<view class="thumbtitle f-s-24 color-333 l-h-34">
									{{item.service_desc||""}}
								</view>
								<view class="locaiton-box color-979797 f-s-24 flex a-i-c">
									<image class="icon" src="/static/images/circle/location-icon.svg" mode=""></image>
									{{item.address_str||""}}
								</view>
								<view class="km-money-btn-box flex a-i-c j-c-b">
									<view class="money-km f-s-24 f-w-b color-2567F3">
										服务范围{{item.service_scope||0}}km
									</view>
									<view class="btn-box all-center f-s-26" @click="$callPhone(item.principal_phone)">
										<image class="icon" src="@/static/images/my/store-phone-icon.svg" mode=""></image>
										拨打
									</view>
								</view>
							</view>
						</view>
					</view>
				</block>
			</view>
		</view>
	</public-view>
</template>

<script>
	import topSelect from "@/components/myComponents/topSelect.vue"
	import {getMerchantList} from "@/utils/pagePublic.js"
	export default {
		components:{
			"top-select":topSelect
		},
		data() {
			return {
				distance_list:["默认距离",'5.0km','10.0km','20.0km'],
				distance:'',
				page_title:"",
				list:[
					{
						id:'1',
						title:"距离优先",
						active:true
					}
				],
				tab_list:[
					{
						id:'0',
						name:"修理"
					},
					{
						id:'1',
						name:'保养'
					}
				],
				tab_id:"0",
				gas_list:[],
				lng:"",
				lat:"",
				distance_text:""
			};
		},
		watch:{
			"$store.state.nav_address":{
				handler(newVal,oldVal) {
					this.gas_list = []
					that.getMerchantList()
				},
				deep:true
			}
		},
		onLoad(options){
			let that = this
			that.page_title = options.title
			that.$location.myGetLocation((res)=>{
				console.log(res)
				// that.gasoline = that.gasoline.concat(that.$store.getters.gasoline)
				that.lng = res.lng
				that.lat = res.lat
				that.getMerchantList()
			},false)
		},
		onPullDownRefresh() {
			this.gas_list = []
			this.getMerchantList()
		},
		methods:{
			changeD(e){
				let index = e.detail.value
				let arr = []
				if(this.distance_list[index] === "默认距离"){
					this.distance_text = ""
				}else{
					this.distance_text = this.distance_list[index]
					arr = this.distance_text.split('.')
				}
				this.distance = arr[0] ||0
				this.gas_list = []
				this.getMerchantList()
			},
			getMerchantList(){
				let that = this,address=this.$store.state.nav_address
				getMerchantList({
					type:1,
					gasoline_ids:[],
					genre:that.tab_id,
					distance:this.distance||0,
					distance_sort:"asc",
					lng:that.lng,
					lat:that.lat,
					province_id:address.provinces.id,
					city_id:address.city.id,
					area_id:address.area.id
				},(res)=>{
					console.log(res)
					that.gas_list = res.data.data
					uni.stopPullDownRefresh()
				}).catch(e=>[
					uni.stopPullDownRefresh()
				])
			},
			changeTabId(item){
				this.tab_id = item.id
				this.gas_list = []
				this.getMerchantList()
			}
		}
	}
</script>
<style lang="scss" scoped>
	.icon{
		width: 20upx;
		height: 20upx;
		margin-left: 20upx;
	}
	.compont-list-box{
		width: 750upx;
		padding: 0 24upx;
		.items{
			margin-bottom: 20upx;
			width: 100%;
			padding: 26upx 28upx 30upx 26upx;
			background: #FFFFFF;
			box-shadow: 0px 8upx 16upx rgba(0, 0, 0, 0.05);
			border-radius: 16upx;
			.center-info{
				width: 100%;
				.info-box{
					.km-money-btn-box{
						width: 100%;
						.btn-box{
							color: #2567F3;
							background: rgba(255, 255, 255, 0.4);
							border: 2upx solid #2567F3;
							border-radius: 8upx;
							width: 120upx;
							height: 48upx;
							.icon{
								width: 26upx;
								height: 26upx;
								margin-right: 10upx;
							}
						}
						.money-km{
							
						}
					}
					.locaiton-box{
						.icon{
							width: 26upx;
							height: 26upx;
							margin-right: 4upx;
						}
					}
					.thumbtitle{
						margin-bottom: 12upx;
					}
				}
				.image{
					width: 188upx;
					height: 188upx;
					border-radius: 8upx;
					margin-right: 13upx;
					background-color: #EFEFEF;
				}
			}
			.top{
				width: 100%;
				margin-bottom: 20upx;
				.juli-box{
					background: #F2F2F2;
					border-radius: 80upx;
					height: 38upx;
					padding: 2upx 12upx;
					.l-icon{
						width: 24upx;
						height: 24upx;
						margin-right: 4upx;
					}
				}
				.compon-icon{
					width: 30upx;
					height: 30upx;
					margin-right: 8upx;
				}
			}
		}
	}
	.tablist{
		.item{
			position: relative;
			margin-right: 54upx;
			.line-bottom{
				width: 36upx;
				height: 8upx;
				background-color: #2567F3;
				position: absolute;
				bottom: -12upx;
			}
		}
		.active{
			font-weight: bold;
			color: #000;
			font-size: 32upx;
		}
		.unacitve{
			color: #6D6D6D;
			font-size: 28upx;
		}
	}
	.top-tab{
		width: 100%;
		padding: 30upx 54upx;
	}
	.content{
		width: 750upx;
	}
</style>
